package com.it.controller;

import com.it.pojo.account;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.support.SessionStatus;

@Controller
@RequestMapping("demo2")
@SessionAttributes(value={"username","password","age"})
public class HelloController {

    @RequestMapping("hello")
    public String hello() {
        return "success";
    }

    @RequestMapping("getBasicParam")
    public String getBasicParam(String username,Integer age) {
        System.out.println(username + ":" + age);
        return "success";
    }

    @RequestMapping(value="getAccount")
    public String getAccount(account account) {
        System.out.println(account);
        return "success";
    }

    @RequestMapping("testRequestParam")
    public String testRequestParam(String username,Integer age) {
        System.out.println(username + ":" + age);
        return "success";
    }

    @RequestMapping("testRequestBody")
    public String testRequestBody(@RequestBody String body) {
        System.out.println(body);
        return "success";
    }

    @RequestMapping("putData")
    public String putData(Model model) {
        model.addAttribute("username","66");
        model.addAttribute("password","66");
        model.addAttribute("age","66");
        return "success";
    }
    @RequestMapping("getData")
    public String getData(ModelMap modelMap) {
        String username = (String) modelMap.get("username");
        String password = (String) modelMap.get("password");
        String age = (String) modelMap.get("age");
        System.out.println(username + ":" + password + ":" + age);
        return "success";
    }

    @RequestMapping("removeData")
    public String removeData(SessionStatus sessionStatus) {
        sessionStatus.setComplete();
        return "success";
    }

    @RequestMapping("testPathVariable/{id}/{username}")
    public String testPathVariable(@PathVariable("id") Integer id,@PathVariable("username")String username) {
        System.out.println(id + ":" + username);
        return "success";
    }
}
